package com.yy.controller;

import com.yy.common.annotation.Log;
import com.yy.common.core.controller.BaseController;
import com.yy.common.core.domain.AjaxResult;
import com.yy.common.core.page.TableDataInfo;
import com.yy.common.enums.BusinessType;
import com.yy.common.utils.poi.ExcelUtil;
import com.yy.domain.ParkCarInoutLogRecord;
import com.yy.service.IParkCarInoutLogRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车辆通行记录Controller
 *
 * @author leige
 * @date 2023-03-10
 */
@RestController
@RequestMapping("/park/record")
public class ParkCarInoutLogRecordController extends BaseController
{
    @Autowired
    private IParkCarInoutLogRecordService parkCarInoutLogRecordService;

    /**
     * 查询车辆通行记录列表
     */
    @PreAuthorize("@ss.hasPermi('park:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkCarInoutLogRecord parkCarInoutLogRecord)
    {
        startPage();
        List<ParkCarInoutLogRecord> list = parkCarInoutLogRecordService.selectParkCarInoutLogRecordList(parkCarInoutLogRecord);
        return getDataTable(list);
    }

    /**
     * 导出车辆通行记录列表
     */
    @PreAuthorize("@ss.hasPermi('park:record:export')")
    @Log(title = "车辆通行记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkCarInoutLogRecord parkCarInoutLogRecord)
    {
        List<ParkCarInoutLogRecord> list = parkCarInoutLogRecordService.selectParkCarInoutLogRecordList(parkCarInoutLogRecord);
        ExcelUtil<ParkCarInoutLogRecord> util = new ExcelUtil<ParkCarInoutLogRecord>(ParkCarInoutLogRecord.class);
        util.exportExcel(response, list, "车辆通行记录数据");
    }

    /**
     * 获取车辆通行记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('park:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(parkCarInoutLogRecordService.selectParkCarInoutLogRecordById(id));
    }

    /**
     * 新增车辆通行记录
     */
    @PreAuthorize("@ss.hasPermi('park:record:add')")
    @Log(title = "车辆通行记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkCarInoutLogRecord parkCarInoutLogRecord)
    {
        return toAjax(parkCarInoutLogRecordService.insertParkCarInoutLogRecord(parkCarInoutLogRecord));
    }

    /**
     * 修改车辆通行记录
     */
    @PreAuthorize("@ss.hasPermi('park:record:edit')")
    @Log(title = "车辆通行记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkCarInoutLogRecord parkCarInoutLogRecord)
    {
        return toAjax(parkCarInoutLogRecordService.updateParkCarInoutLogRecord(parkCarInoutLogRecord));
    }

    /**
     * 删除车辆通行记录
     */
    @PreAuthorize("@ss.hasPermi('park:record:remove')")
    @Log(title = "车辆通行记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(parkCarInoutLogRecordService.deleteParkCarInoutLogRecordByIds(ids));
    }
}
